home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
video
/
trojka.tgz
/
trojka.tar
/
trojka
/
trojka.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-20
|
5KB
|
327 lines
/*
* @(#) TROJKA main file
* created: 4.iii.1992
* modified: 20.iii.1992
*/
#include <stdio.h>
#include <curses.h>
#include "trojka.h"
#include "hiscore.h"
static char INFO[] = "@(#) trojka (c) 1989-1995 by Maarten Los";
int play(),
dropblock(),
multscore(),
speedup(),
initialize(),
resetgame(),
resetblock(),
check_speed(),
check_mesg(),
resetfield(),
getopt();
struct scorefile *sfile;
char field[VIRT_XSIZE][VIRT_YSIZE]; /* virtual screen */
unsigned long
score,
mesg_score,
blocks,
wipes,
mesg_time,
speedbonus; /* bonus multiplier depending on speed */
flag stopgame, /* flag quit game */
quit, /* flag quit trojka */
mesg_showed,
curses_installed;
int shape, /* index of block */
xpos, /* virtual coordinates of the falling block */
ypos, /* conversion to on-screen coordinates takes */
last_xpos, /* place in 'makeblock()' */
last_ypos,
statx,
x_min, x_max,
mesg_count, /* cookie-counter */
stacklevel, /* level of stack */
blockwidth, /* width of a block in characters */
level,
speed, /* game speed */
speed_switch, /* number of fallen blocks the speed is increased */
trojkas,
position, /* position in the highscore table */
Pause, /* game speed in milliseconds */
xloc[VIRT_XSIZE], /* array with the x-coordinates */
yloc[VIRT_YSIZE],
block_count[BLOCKS];
main(argc, argv)
int argc;
char **argv;
{
sfile = (struct scorefile *)malloc(FILE_SIZE);
if(sfile == NULL)
quit_prog("Not enough memory to hold scores.");
readscores();
getopt(argc, argv);
initcurses();
initialize();
while(!quit) {
titlescreen();
if (!quit) {
speed = (int)selectspeed();
if (!quit) {
resetgame();
build();
refresh();
play();
}
}
}
quit_prog("See you around in the Trojka-zone...");
}
int play()
{
resetblock(); /* reset x-y coordinates */
showspeed(speed);
speed_switch = SPEED_SWITCH * (speed + 1);
Pause = 200 - (speed + 1)*15;
speedbonus = (unsigned long)(speed+1);
while(!stopgame)
{
wipeblock(last_xpos, last_ypos);
makeblock(xpos, ypos, shape);
move(0,0);
refresh();
last_xpos = xpos;
last_ypos = ypos;
delay(Pause); /* game speed */
ypos--;
switch(getkey()) { /* key control */
#ifdef HACK
case 't':
score += 10000;
showscore();
break;
#endif
case LEFT:
case VILEFT:
if((xpos > 0) && (field[xpos-1][ypos] == CLEAR))
xpos--;
break;
case RIGHT:
case VIRIGHT:
if((xpos < VIRT_XSIZE-1)
&& (field[xpos + 1][ypos] == CLEAR))
xpos++;
break;
case DROP:
case SPACE :
case VIDROP:
case INSDROP:
dropblock();
break;
case QUIT:
stopgame = TRUE;
quit = FALSE;
break;
case REDRAW:
redraw();
break;
case VISPEEDUP:
case SPEEDUP:
speedup();
break;
} /* case */
if (field[xpos][ypos] != CLEAR) {
field[xpos][ypos+1] = shape;
block_count[shape-1]++;
/* scan() returns the stacklevel */
if(scan() < PLM_TOP) {
multscore((unsigned long)shape);
blocks++;
check_speed();
check_mesg();
statistics();
showscore();
resetblock();
} else {
/* GAME OVER */ wipemesg();
stopgame = TRUE;
quit = FALSE;
}
}
}
gameover();
}
int dropblock()
{
score += (unsigned long)((ypos * speedbonus) / 5);
wipeblock(xpos, ypos+1);
while(field[xpos][ypos]==CLEAR)
ypos--;
makeblock(xpos, ypos+1, shape);
refresh();
}
int multscore(mult)
unsigned long mult;
{
score += (unsigned long)((mult * speedbonus + level) / 3);
}
int speedup()
{
if(speed < MAXSPEED) {
speed++;
showspeed(speed);
speedbonus = (unsigned long)(speed+1);
Pause = 200 - (speed+1)*15;
speed_switch = SPEED_SWITCH * (speed + 1);
}
}
int initialize()
{
int i;
position = NUMSCORES + 1;
x_min = X_MIN;
x_max = X_MAX;
statx = STATX;
blockwidth = 4;
resetfield();
reset_f(); /* reset shadow buffer in scan.c */
for(i = 0; i < VIRT_XSIZE; i++)
xloc[i] = (i * blockwidth) + x_min;
for(i = PLM_TOP; i >= PLM_BOTTOM; i--)
yloc[i] = (PLM_TOP - i) + 1;
quit = FALSE;
}
int resetgame()
{
int i;
setrandom();
resetfield();
for(i = 0; i < BLOCKS; i++)
block_count[i] = 0;
score = 0;
mesg_count = 0;
mesg_score = (unsigned long)MESG_SWITCH;
mesg_time = 0;
blocks = 0;
trojkas = 0;
wipes = 0;
stopgame = FALSE;
quit = FALSE;
level = 1;
}
int resetblock()
{
ypos = PLM_TOP;
xpos = VIRT_MIDDLE;
last_xpos = xpos;
last_ypos = ypos;
shape = getrandom(BLOCKS) + 1;
}
int resetfield()
{
int x,y;
for(x = 0; x < VIRT_XSIZE; x++) /* clear virt. field */
for(y = 1; y < VIRT_YSIZE; y++)
field[x][y] = CLEAR;
for(x = 0;x < VIRT_XSIZE; x++) /* fill bottom-line */
field[x][0] = -1;
stacklevel = 0;
}
int check_speed()
{
if (blocks > speed_switch)
speedup();
}
int check_mesg()
{
if((score > mesg_score) && (mesg_count < MESGS) && (stacklevel <= 9))
{
wipemesg();
showmesg(mesg_count++);
mesg_showed = TRUE;
mesg_score = ((unsigned long)MESG_SWITCH + score);
}
if(mesg_showed) {
mesg_time++;
if(mesg_time > MAX_MESG_TIME) {
wipemesg();
mesg_time = 0;
mesg_showed = 0;
}
}
}
int getopt(argc, argv)
int argc;
char **argv;
{
if(argc > 1) {
if(!strcmp(argv[1], "-s"))
scorelist();
else
fprintf(stderr,"Usage: trojka [-s]\n");
exit(0);
}
}